<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div,p{
            width: 100px;
            height: 100px;
            background-color: red;
            margin: 20px;
        }
        div#bottom{
            width: 200px;
            height: 200px;
            background-color: blue;
        }
    </style>
    <script>
        window.onload=function(){
           var top=document.getElementById('top');
           var bottom=document.getElementById('bottom');
           top.ondragstart=function(event){
            //    console.log('开始拖放');
               var data=event.dataTransfer;
               data.setData('key',this.id);
            //    console.log(data.getData('key'));

           }
        //    top.ondrag=function(){
        //        console.log('正在被拖放');
        //    }
        //    top.ondragend=function(){
        //        console.log('鼠标松开');
        //    }
        //    bottom.ondragenter=function(){
        //        console.log('有元素进来啦');
        //    }
           bottom.ondragover=function(event){
               event.preventDefault();
               console.log('有元素在我内部移动');
           }
           bottom.ondrop=function(event){
            var data=event.dataTransfer;
            //获取拖拽元素的id
            var id=data.getData('key');
            //根据id获取dom对象
            var top=document.getElementById(id);
            //将拖拽元素放置在目标放置元素内部
            this.appendChild(top);
            //    console.log('有元素在我内部被放置啦');
           }
        }
    </script>
</head>
<body>
   <div id="top" draggable="true"></div>
   <div id="bottom"></div>
</body>
</html>